Creating a gambas2 program, step by step, a telephone index

From : http://listingambas.blogspot.com/2011/06/introducir-datos-textos.html


Entering Data: Texts

SetFocus
To enter the data we have to move through the textboxes.
So, we press Tab Hierarchy: (see Figure 1, red area of point 4)

Object hierarchy

With up and down arrows, we can sort the controles so that, at runtime, browsing let's move from a textbox to another when pressing the key " tab ".
To make that the move to a specified next textbox (which we want to enter the data in) will occur also when pressing "Enter" or "Return", we must use such a following "code":
PUBLIC SUB TextBoxWhereWeAre_KeyPress ()
    IF Key . code = Key . enter OR Key . code = Key . Return THEN
        TextBoxToReach . SetFocus
    ENDIF
END


Where TextBoxWhereWeAre, is the TextBox where the cursor is presently, and TextBoxNext the TextBox where we want to direct the cursor when leaving the current TextBox.

In our program, it would be the following code:
 
PUBLIC SUB TextBoxDNI_KeyPress ()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
TextBoxName.SetFocus
ENDIF
END

PUBLIC SUB TextBoxName_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxSurname.SetFocus
ENDIF
END

PUBLIC SUB TextBoxSurname_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxcompany.SetFocus
ENDIF
END


PUBLIC SUB TextBoxCompany_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
     TextBoxPosition.SetFocus
ENDIF
END


PUBLIC SUB TextBoxPosition_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
     TextBoxJobTel.SetFocus
ENDIF
END


PUBLIC SUB TextBoxJobTel_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxJobMobile.SSetFocus
ENDIF
END


PUBLIC SUB TextBoxJobMobile_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxPrivateTel.SetFocus
ENDIF
END


PUBLIC SUB TextBoxPrivateTel_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxPrivateMobile.SetFocus
ENDIF
END


PUBLIC SUB TextBoxPrivateMobile_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxFax.SetFocus
ENDIF
END


PUBLIC SUB TextBoxFax_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxMail.SetFocus
ENDIF
END


PUBLIC SUB TextBoxMail_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxDate.SetFocus
ENDIF
END


PUBLIC SUB TextBoxDate_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxWEB.SetFocus
ENDIF
END


PUBLIC SUB TextBoxWeb_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxAddress.SetFocus
ENDIF
END


PUBLIC SUB TextBoxAddress_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    TextBoxComments.SetFocus
ENDIF
END


PUBLIC SUB TextBoxComments_KeyPress()
IF Key. code = Key. enter OR Key. code = Key. Return THEN
    ButtonValid.SetFocus
ENDIF
END